﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Script.Serialization;
using Easy.Operation;
using Microsoft.JScript;
using Newtonsoft.Json;
using Easy.BLL;

namespace Easy.Web.Service.Entity
{
    /// <summary>
    /// AddViewMap 的摘要说明
    /// </summary>
    public class AddViewMap : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string json = context.Request["view"];


            ResultClass rc = new ResultClass();

            try
            {

                JavaScriptSerializer jss = new JavaScriptSerializer();

                ViewMapClass view = jss.Deserialize<ViewMapClass>(json);
                view.ViewTemplete = GlobalObject.unescape(view.ViewTemplete);

                string saved_guid = EntitySetting_Function.AddViewMap(view);
                //存储Js关系
                JsHubBLL bll = new JsHubBLL();
                bll.ModifyViewJsRelation(context.Request["EntityName"].ToLower(), view.Name, JsonConvert.DeserializeObject<List<Guid>>(context.Request["jslist"]));


                rc.Result = 0;
                rc.Remark = saved_guid;

            }

            catch (Exception e)
            {
                rc.Result = 1;
                rc.Remark = e.Message;
            }
            


            context.Response.Write(rc.ToJson());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}